﻿namespace Jsl.FxCop
{
    using Jsl.FxCop.Targets;
    using Microsoft.VisualStudio.CodeAnalysis.Extensibility;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class TestCallBaseDispose
    {
        [TestMethod]
        public void No_Disose()
        {
            new CallBaseDispose()
                .RunMethodRule(typeof(CallBaseDisposeTarget_no_Dispose), "Dummy")
                .HasNoMoreProblems();
        }

        [TestMethod]
        public void Non_virtual_Dispose_produces_no_problems()
        {
            new CallBaseDispose()
                .RunMethodRule(typeof(CallBaseDisposeTarget_non_virtual_Dispose), "Dispose")
                .HasNoMoreProblems();
        }

        [TestMethod]
        public void Abstract_dispose_produces_no_problems()
        {
            new CallBaseDispose()
                .RunMethodRule(typeof(CallBaseDisposeTarget_abstract_Dispose), "Dispose")
                .HasNoMoreProblems();
        }

        [TestMethod]
        public void Virtual_Dispose_produces_no_problems()
        {
            new CallBaseDispose()
                .RunMethodRule(typeof(CallBaseDisposeTarget_virtual_Dispose), "Dispose")
                .HasNoMoreProblems();
        }

        [TestMethod]
        public void Dispose_doesnt_call_base_produces_problem()
        {
            new CallBaseDispose()
                .RunMethodRule(typeof(CallBaseDisposeTarget_Dispose_doesnt_call_base), "Dispose")
                .HasProblem(
                    100,
                    FixCategories.NonBreaking,
                    MessageLevel.Error,
                    "Add a call to base.Dispose as the last line of the method.")
                .HasNoMoreProblems();
        }

        [TestMethod]
        public void Virtual_Dispose_does_call_base_no_problems()
        {
            new CallBaseDispose()
                .RunMethodRule(typeof(CallBaseDisposeTarget_Dispose_does_call_base), "Dispose")
                .HasNoMoreProblems();
        }
    }
}